package com.fxd.study.spring.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author xudongfu
 * @date 2023/02/07
 */
public class Test {

    public static void main(String[] args) {

        Chinese chinese = new Chinese();

        People proxyInstance = (People) Proxy.newProxyInstance(chinese.getClass().getClassLoader(),
                chinese.getClass().getInterfaces(), new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                        System.out.println("before do something");

                        method.invoke(chinese, args);

                        System.out.println("after do something");

                        return null;
                    }
                });

        proxyInstance.say("hello~~");
        proxyInstance.eat("fruit~~");

    }
}
